package logic

import (
	"context"

	"lottery-zero/internal/svc"
	"lottery-zero/internal/types"

	"lottery-zero/internal/model"

	"github.com/tal-tech/go-zero/core/logx"
)

type SsqlatestLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSsqlatestLogic(ctx context.Context, svcCtx *svc.ServiceContext) SsqlatestLogic {
	return SsqlatestLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SsqlatestLogic) Ssqlatest() (*types.SsqLatestReply, error) {

	var ssqBall model.DoubleBall
	tx := l.svcCtx.PGDB.Model(&model.DoubleBall{}).Order("open_date desc").First(&ssqBall)
	return &types.SsqLatestReply{Qihao: ssqBall.Qihao, OpenDate: ssqBall.OpenDate.Format("2006-01-02 15:04:05"), RedBall: ssqBall.RedBall, BlueBall: ssqBall.BlueBall}, tx.Error
}
